package main

import (
	"dbus-gen/udisks2"
	"dlib/dbus"
	"fmt"
)

func main() {
	driList := []dbus.ObjectPath{}
	obj := udisks2.GetObjectManager("/org/freedesktop/UDisks2")
	managers := obj.GetManagedObjects()

	for _, value := range managers {
		if _, ok := value["org.freedesktop.UDisks2.Block"]; ok {
			v := value["org.freedesktop.UDisks2.Block"]["Drive"]
			path := v.Value().(dbus.ObjectPath)
			if path != dbus.ObjectPath("/") {
				fmt.Printf("path: %v\n", path)
				flag := false
				l := len(driList)
				for i := 0; i < l; i++ {
					if driList[i] == path {
						flag = true
						break
					}
				}
				if !flag {
					driList = append(driList, path)
				}
			}
		}
	}

	totalSize := uint64(0)
	for _, driver := range driList {
		_, driExist := managers[driver]
		rm, _ := managers[driver]["org.freedesktop.UDisks2.Drive"]["Removable"]
		fmt.Println("is ok:", driExist, rm)
		if driExist && !(rm.Value().(bool)) {
			size := managers[driver]["org.freedesktop.UDisks2.Drive"]["Size"]
			fmt.Printf("size: %v\n", size)
			totalSize += uint64(size.Value().(uint64))
		}
	}

	fmt.Printf("Total Size: %v\n", totalSize)
}
